<!doctype html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>微信管理</title>

  <!-- Disable tap highlight on IE -->
  <meta name="msapplication-tap-highlight" content="no">

  <link href="styles/bootstrap.min.css" rel="stylesheet">
  <link href="styles/dashboard.css" rel="stylesheet">
  <link href="scripts/tinymce/themes/modern/theme.min.js" rel="stylesheet">
  <style>

  </style>
</head>

<body>
  <!-- Add your site or app content here -->
  <nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
        <a class="navbar-brand" href="/">微信管理</a>
      </div>
      <div id="navbar" class="navbar-collapse collapse">
        <ul class="nav navbar-nav navbar-right">
          <li><a href="/">首页</a></li>
          <li><a href="/userinfo.html">微信号管理</a></li>
          <li><a href="/ads_list.html">广告列表</a></li>
          <li><a href="/logout.html">登出</a></li>
        </ul>
      </div>
    </div>
  </nav>

  <div class="container-fluid">
    <div class="row">
      <div class="col-sm-3 col-md-2 sidebar">
        <ul class="nav nav-sidebar">
          <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
        </ul>
      </div>
      <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <h1 class="page-header">编辑文章</h1>
        <div>
          <div style="display: none;">
            选择广告：<select id="title_id">
          <option value="-1">新增</option>
        </select>
          </div>
          标题:<input id='title' placeholder="请输入标题" style="width:80%;">
          <textarea id="tarea"></textarea>
          <h2 class="page-header">提交广告</h2>
          <textarea id="ttarea"></textarea>
          <button onclick="postData();">提交</button>
        </div>
      </div>
    </div>
  </div>

  <!-- Built with love using Web Starter Kit -->
  <script src="scripts/pace.min.js"></script>
  <script src="scripts/jquery.min.js"></script>
  <script src="scripts/bootstrap.min.js"></script>
  <script src="scripts/tinymce/tinymce.min.js"></script>
  <script src="scripts/tinymce/langs/zh_CN.js"></script>
  <script src="scripts/config.js"></script>
  <script>
    checkLogin();

    var news_editor = tinymce.init({
      selector: '#tarea',
      height: 500,
      plugins: [
        'advlist autolink lists link image charmap preview anchor',
        'searchreplace visualblocks code fullscreen',
        'insertdatetime media table contextmenu paste code'
      ],
      toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
      content_css: [
        '//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
        '//www.tinymce.com/css/codepen.min.css'
        //styles/wx_css/not_in_mm.min.css',
        //'styles/wx_css/page_mp_article_improve.min.css'
      ]
    });
    var ad_editor = tinymce.init({
      selector: '#ttarea',
      height: 500,
    })
    var query = GetRequest();
    var aid = query['aid'];

    function getClassifyAds() {
      $.get(server_host + '/ad/' + cid, function(data) {
        if (data.info.code == 200) {
          var items = data.item;
          var options = '<option value="-1">新增</option>';
          if (items.length > 0) {
            for (var i = 0; i < items.length; i++) {
              options += "<option value='" + i + "'>" + items[i].title + "</option>"
            }
          }
          $('#title_id').html(options);
        }
      }, 'json')
    }

    function postData() {
      //var title_id = $('#title_id').val();
      var title = $('#title').val();
      var news = tinyMCE.get('tarea').getContent();
      var ads = tinyMCE.get('ttarea').getContent();
      $.post(server_host + '/news/content/' + aid, {
        'content': news,
        'title': title,
        'ad': ads
      }, function(data) {
        if (data.info.code = 200) {
          history.back(-1);
        } else {
          console.log(data);
        }
      }, 'json');
    }

    function getOld(aid) {
      $.get(server_host + '/news/content/' + aid, function(data) {
        if (data.info.code = 200) {
          $('#title').val(data.item.title);
          tinymce.get('tarea').setContent(data.item.content);
        } else {
          console.log(data);
        }
      }, 'json');
    }
    setTimeout("getOld('" + aid + "')", 2000)
  </script>
</body>

</html>